package com.zhongkai.app.controller;

import com.zhongkai.app.service.AppGuardService;
import com.zhongkai.app.service.SetUnitService;
import com.zhongkai.app.service.WeiXiuLoginService;
import com.zhongkai.model.utils.ZhongkaiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 维修端登录
 */
@Controller
public class WeiXiuLoginController {

    @Autowired
    private WeiXiuLoginService weiXiuLoginService;

    @Autowired
    private SetUnitService setUnitService;

    @Autowired
    private AppGuardService appGuardService;

    /**
     * 维修端登录
     *
     * @param phone 手机号
     * @param par   参数
     * @param types 登录方式
     */
    @RequestMapping(value = "/weixiu/puk", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addToken(String phone, String par, String types) {

        ZhongkaiResult result = weiXiuLoginService.wxLogin(phone, par, types);
        // User user = new User("我的名字", "我是密码");
        //userService.save(user);
        // ZhongkaiResult zhongkaiResult = tokenService.getUserToken("22");

        return result;
    }


    /**
     * 维修APP为设备绑定用户
     *
     * @param unit_uuid    设备uuid
     * @param user_name    用户姓名
     * @param user_phone   用户手机号
     * @param user_number  身份证号
     * @param sex          性别 1男 2女
     * @param longitude    经度
     * @param latitude     纬度
     * @param province     省
     * @param city         市
     * @param country      区
     * @param town         乡镇
     * @param address      详细地址
     * @param pact_num     合同编号
     * @param set_vol_uuid 大客户uuid 传0代表没有
     * @param set_alias    设备别名
     * @param ope_user     操作人员姓名
     * @param ope_uuid     操作人员uuid
     */
    @RequestMapping(value = "/weixiu/bound", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult bound_user(
            String unit_uuid, String user_name, String user_phone, String user_number, @RequestParam(defaultValue = "1") String sex, String longitude, String latitude, String province, String city,
            String country, String town, String address, String pact_num, @RequestParam(defaultValue = "0") String set_vol_uuid, String set_alias, String ope_user, String ope_uuid
            , HttpServletRequest httpServletRequest
    ) {


        // Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult zhongkaiResult = setUnitService.bound_user(unit_uuid, user_name, user_phone, user_number, sex, longitude, latitude, province, city, country, town, address, ope_user, ope_uuid, pact_num, set_vol_uuid, set_alias);


        return zhongkaiResult;
    }


    /**
     * 维修端获取大客户列表
     */
    @RequestMapping(value = "/weixiu/puk/get_big_user", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult getBigUserList() {

        ZhongkaiResult result = appGuardService.getBigUserList();
        // User user = new User("我的名字", "我是密码");
        //userService.save(user);
        // ZhongkaiResult zhongkaiResult = tokenService.getUserToken("22");

        return result;
    }
}
